
window.onload = function (){
    initInfo();
    findAll();

}

function initInfo(){
    axios.get("/user/getLoginUser").then(resp=>{
        if(resp.data == ""){
            $("empty-div").innerHTML = "请先<a href= '/login.html'>登录</a>"
        }else {
            $("empty-div").innerHTML = "登录用户：" + resp.data.username +
                " 邮箱：" + resp.data.email + " 头像：<img src='/img/" + resp.data.imgPath + "' style='width: 40px; height: 40px;'>"
        }
    })
}

// JavaScript 中的 findAll 函数
function findAll() {
    axios.get("/channel/findAll").then(resp=>{
        let data = resp.data;
        let info="";
        data.forEach(rs=>{
            info+=`<tr>
                <td><a href="/post.html?id=${rs.id}">${rs.name}</td>
                <td>${rs.description}</td>
                <td>${rs.count}</td>
            </tr>`
        })
        $("channelList").innerHTML=info
    })
}